﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SchEdu.Framework.Algorithm;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace Johnson
{
    public class JohnsonAlgorithm : Algorithm
    {
        public JohnsonAlgorithm()
        {
        }

        public JohnsonAlgorithm(SchEduData schEduData) 
            :base(schEduData)
        {
        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();

            validators.Add(new WorkCenterValidator(SchEduData,2,2));
            validators.Add(new MachinePerWorkCenterValidator(SchEduData, 1, 1));
            validators.Add(new OperationWorkCenterValidator(SchEduData));
            validators.Add(new OperationPerOrderValidator(SchEduData, 2, 2));
            validators.Add(new OperationSequenceNoValidator(SchEduData));
            validators.Add(new FlowShopOperationValidator(SchEduData));

        }

        protected override void Logic()
        {
            OperationList c1 = new OperationList();
            OperationList c2 = new OperationList();
            SchEduDataSet.WorkCenterRow workCenter1 = WorkCenters[0];
            SchEduDataSet.WorkCenterRow workCenter2 = WorkCenters[1];

            Operations.SortByProcessingTime();

            foreach (SchEduDataSet.OperationRow op in Operations)
            {
                if (op.WorkCenterID == workCenter1.ID)
                {
                    c1.Add(op);
                }
                else
                {
                    c2.Insert(0, op);
                }
            }

            OperationList c = new OperationList();
            c.AddRange(c1);
            c.AddRange(c2);

            // set start/end dates
            SetOperationDates();
        }

        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Johnson";
                aboutInfo.Description = Resources.JohnsonAlgorithmDescription;
                aboutInfo.Guid = new Guid("{400A306B-4D62-4e50-BF17-ECB32A4F7D60}");
                return aboutInfo;
            }
        }

    }
}
